<?php

namespace app\index\controller;

use app\common\model\Ad;
use app\common\model\Question;
use think\Controller;
use think\facade\Session;
use think\Request;

class Search extends Base
{
    public function geturl()
    {
        $data = request()->param('key');
        if (!isset($data)) {
            $data = '请输入关键词';
        }
        $url = url('index/search/search', ['key' => $data]);
        return $this->redirect($url);
    }

    public function search()
    {
        $que = new Question();
        //搜索的内容
        $s = $this->request->param('key');

        //seo信息
        $site_info =  seo($s . '-搜索试题', 5);
        //搜索结果 - 只展示50条
        $list = $que->search($s);
        //最热推荐
        $hot_list = $que->get_hotList();
        //随机推荐
        $rand_list = $que->get_rand();

        if (count($list) < 1) {
            $this->assign([
                'no_data' => '1'
            ]);
        } else {
            $this->assign([
                'no_data' => '0'
            ]);
        }

        $this->assign([
            'site_seo' => $site_info,
            'list' => $list,
            'search' => $s,
            'hot_list' => $hot_list,
            'rand_list' => $rand_list
        ]);
        return $this->fetch();
    }
}
